﻿package com.tris
{
	import flash.display.Sprite;
	import flash.events.*;
	import org.papervision3d.cameras.Camera3D;
	import org.papervision3d.render.BasicRenderEngine;
	import org.papervision3d.scenes.Scene3D;
	import org.papervision3d.view.Viewport3D;
	import org.cove.ape.*;
	
	/**
	* ...
	* @author DefaultUser (Tools -> Custom Arguments...)
	*/
	public class PapervisionBase extends Sprite
	{
		protected var viewport:Viewport3D;
		protected var scene:Scene3D;
		protected var renderer:BasicRenderEngine;
		protected var camera:Camera3D;
		protected var defaultGroup:Group = new Group();
		
		public function PapervisionBase(camX:Number=0, camY:Number=300, camZ:Number=-500) 
		{
			// Create viewport
			viewport = new Viewport3D(600, 600, true, true);
			addChild( viewport );
			
			renderer = new BasicRenderEngine();
			
			// Create scene
			scene = new Scene3D();
			
			// Create camera
			camera = new Camera3D();
			camera.zoom = 5;
			camera.focus = 100;
			camera.x += camX;
			camera.z += camZ;
			camera.y += camY;
			
			addEventListener( Event.ENTER_FRAME, loop );
			initApe();
		}
		
		protected function initApe():void
		{
			APEngine.init(1/4);
			APEngine.container = this;
			APEngine.addForce( new VectorForce(false, 0, 15) );
			
			defaultGroup.collideInternal = true;
			APEngine.addGroup(defaultGroup);
		}
		
		public function loop(event:Event):void 
		{
			renderer.renderScene(scene, camera, viewport);
		}
	}
	
}